import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '../store';

// 把这段代码直接粘贴到router/index.js中的Vue.use(VueRouter)之前
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch(err => { })
};

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: 'searchpopup',
        component: () => import(/* webpackChunkName: "searchpopup" */ '../views/Searchpopup.vue')
      }
    ],
    meta: {
      tabbarActive: 0,
      isShowTabbar: true
    }
  },
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
  {
    path: '/topic',
    component: () => import(/* webpackChunkName: "topic" */ '../views/Topic.vue'),
    meta: {
      tabbarActive: 1,
      isShowTabbar: true
    }
  },
  {
    path: '/category',
    component: () => import(/* webpackChunkName: "category" */ '../views/Category.vue'),
    meta: {
      tabbarActive: 2,
      isShowTabbar: true
    }
  },
  {
    path: '/cart',
    component: () => import(/* webpackChunkName: "cart" */ '../views/Cart.vue'),
    meta: {
      tabbarActive: 3,
      isShowTabbar: true
    }
  },
  {
    path: '/user',
    component: () => import(/* webpackChunkName: "user" */ '../views/User.vue'),
    meta: {
      tabbarActive: 4,
      isShowTabbar: true
    }
  },
  {
    path: '/productdetail',
    component: () => import(/* webpackChunkName: "detail" */ '../views/ProductDetail.vue'),
    meta: {
      isShowTabbar: false
    }
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  // console.log('to', to);
  // console.log('from', from);
  if (to.path == '/home') {
    store.commit('showshadow/chanIsShowShadow', false);
  }
  next();
})

export default router
